package com.javaeedev.lightweight.mvc.interceptor;

import java.util.Map;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import com.adam.framework.util.BeanUtil;
import com.google.inject.Singleton;
import com.javaeedev.lightweight.mvc.Action;
import com.javaeedev.lightweight.mvc.ActionContext;
import com.javaeedev.lightweight.mvc.Interceptor;
import com.javaeedev.lightweight.mvc.InterceptorChain;
import com.javaeedev.lightweight.mvc.Order;

@Singleton
@Order(0)
public class ParameterInterceptor implements Interceptor {
	private final Log log = LogFactory.getLog(getClass());

	public void intercept(Action action, InterceptorChain chain) throws Exception {
		// sample of using transaction:
		log.info("Begin Populate parameter...");
		Map<?,?> requestParameterMap = ActionContext.getActionContext().getRequest().getParameterMap();
		BeanUtil.getInstance().populate(action, requestParameterMap);

		chain.doInterceptor(action);
		log.info("populate complete");
	}
}
